package com.jss.lanouhn.fristapp.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.activity.SelecterDetails;
import com.jss.lanouhn.fristapp.modles.SelecterInfo;
import com.squareup.picasso.Picasso;

/**
 * Created by lanouhn on 16/8/24.
 */
public class SelecterAdapter extends RecyclerView.Adapter<SelecterAdapter.SelecterViewHolder>{
    private Context mContext;
    private SelecterInfo selecterInfo;

    public SelecterAdapter(Context mContext, SelecterInfo selecterInfo) {
        this.mContext = mContext;
        this.selecterInfo = selecterInfo;
    }

    @Override
    public SelecterViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_selecte_grid,null);
        SelecterViewHolder holder=new SelecterViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(SelecterViewHolder holder, int position) {
        final SelecterInfo.DataBean.ItemsBean beans=selecterInfo.getData().getItems().get(position);

        Picasso.with(mContext).load(beans.getData().getCover_image_url()).into(holder.iv_selecter);
        holder.tv_info.setText(beans.getData().getName());
        holder.tv_money.setText("￥"+beans.getData().getPrice());
        holder.tv_likes.setText(beans.getData().getFavorites_count()+"");

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext,SelecterDetails.class);
                intent.putExtra("id",beans.getData().getId()+"");
                intent.putExtra("url",beans.getData().getPurchase_url());
                mContext.startActivity(intent);

            }
        });

    }

    @Override
    public int getItemCount() {

        return selecterInfo.getData().getItems().size();
    }

    public class SelecterViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_selecter;
        private TextView tv_info,tv_money,tv_likes;

        public SelecterViewHolder(View itemView) {
            super(itemView);
            iv_selecter= (ImageView) itemView.findViewById(R.id.iv_item_selecter);
            tv_info= (TextView) itemView.findViewById(R.id.tv_item_selecter);
            tv_money= (TextView) itemView.findViewById(R.id.tv1_item_selecter);
            tv_likes= (TextView) itemView.findViewById(R.id.tv2_item_selecter);
        }
    }


}
